function ObjOut = addfromStruct(Obj,strArray)
%addfromStruct - add values to an object from a struct array
%
%       ObjOut = addfromStruct(Obj,strArray)
% 
% This function adds the values in the struct array strArray to the 
% properties of the object (struct array) Obj whose fields have the
% same name.
% If strArray is empty or threre are no strArray fields having the same
% name of an Obj property, ObjOut = Obj.  
% This function works in the same way if Obj is a struct variable.

% G. Teza, 2022

if isempty(strArray)
    ObjOut = Obj;
    return
end

fo = fields(Obj);
nfo = numel(fo);

fa = fields(strArray);

ObjOut = Obj;

for k = 1:nfo
    fok = fo{k};
    Ifok = strcmpi(fok,fa);
    if sum(Ifok) == 1
        ObjOut.(fok) = strArray.(fa{Ifok}); 
    end
end